1 00:00:00,740 --> 00:00:01,700 Welcome back. 2 00:00:01,700 --> 00:00:02,780 In this lecture. 3 00:00:02,780 --> 00:00:08,900 We're going to now start working on the shop section of our GUI by adding game passes and implementing 4 00:00:08,900 --> 00:00:11,390 those game passes in our scripts. 5 00:00:11,390 --> 00:00:17,510 If you remember inside of our starting menu GUI, let me go ahead and enable UI visibility. 6 00:00:17,510 --> 00:00:24,050 We had a store frame and inside of here there are two game passes that I would like our players to buy. 7 00:00:24,050 --> 00:00:29,120 We're going to have one game pass, which will give players an upgraded golden knife that they will 8 00:00:29,120 --> 00:00:34,820 spawn with to deal more damage to zombies, and then the other game pass is going to be a faster reload 9 00:00:34,820 --> 00:00:37,070 speed for all of their guns. 10 00:00:37,070 --> 00:00:42,320 So we're going to have to script on the client when they press these buy buttons to let the server know, 11 00:00:42,320 --> 00:00:45,050 hey, we want to purchase this particular Game Pass. 12 00:00:45,050 --> 00:00:49,190 The server is going to prompt them to purchase it, and if they purchase the Game Pass, then we're 13 00:00:49,190 --> 00:00:52,760 going to give them the benefits associated with that game Pass. 14 00:00:52,760 --> 00:00:58,100 We're also going to check for when players join our game, see if they already own these game passes, 15 00:00:58,100 --> 00:01:01,070 and if they do, we'll give them those benefits. 16 00:01:01,070 --> 00:01:05,150 So let me go ahead and re hide this and disable UI visibility. 17 00:01:06,160 --> 00:01:11,530 And back in the creator dashboard, we can go ahead and create a game pass for our game. 18 00:01:11,530 --> 00:01:16,780 I'm back inside of my wave game, and we can head to the monetization tab, and there's a section for 19 00:01:16,780 --> 00:01:17,890 Game Passes. 20 00:01:17,890 --> 00:01:21,880 And inside of here I haven't created any, but we're going to create a new Game Pass. 21 00:01:22,870 --> 00:01:29,410 I'm going to name this game Pass My Golden Knife, and I'll just give it a brief description of like. 22 00:01:29,740 --> 00:01:39,310 This pass will give you access to an upgraded golden knife that deals more damage to zombies. 23 00:01:39,310 --> 00:01:44,380 We'll say something like that, and then we can also go ahead and add an image for your Game pass as 24 00:01:44,380 --> 00:01:44,920 well. 25 00:01:45,470 --> 00:01:47,210 So I just added a very basic image. 26 00:01:47,210 --> 00:01:48,020 It doesn't really matter. 27 00:01:48,020 --> 00:01:51,470 You can add whatever image you would like for your game pass, but then once you're done with that, 28 00:01:51,470 --> 00:01:53,930 we can go ahead and hit Create Pass. 29 00:01:55,830 --> 00:02:01,110 And then once we're done with that, we want to go ahead and actually select this game pass. 30 00:02:01,110 --> 00:02:03,300 And then we want to go to the sales section. 31 00:02:03,300 --> 00:02:05,430 And then we want to mark it as for sale. 32 00:02:05,430 --> 00:02:07,440 And then you can go ahead and set a price in here. 33 00:02:07,440 --> 00:02:09,210 Make sure it's a reasonable price. 34 00:02:09,210 --> 00:02:11,910 I'm just going to set mine to 99 Robux. 35 00:02:11,910 --> 00:02:13,500 We'll hit save changes. 36 00:02:14,210 --> 00:02:18,710 And now what we can go ahead and do is get the asset ID for this Game Pass. 37 00:02:18,710 --> 00:02:19,850 We'll copy that. 38 00:02:20,610 --> 00:02:25,050 And now back inside of studio, I'm going to go ahead and duplicate the badge enum. 39 00:02:25,050 --> 00:02:29,010 And instead I'm going to call this one my Game Pass enum. 40 00:02:29,010 --> 00:02:34,230 And inside of my Game Pass enum, I'm going to delete this, but instead replace it with all the game 41 00:02:34,230 --> 00:02:35,700 passes that can be purchased. 42 00:02:35,700 --> 00:02:38,430 For example, our Knife game pass. 43 00:02:38,430 --> 00:02:42,960 I'll set it equal to a table with the associated ID of that Game Pass. 44 00:02:42,960 --> 00:02:47,610 I'll paste that there, and then I'm also going to give a name for my game pass. 45 00:02:47,610 --> 00:02:50,400 I'll just call it the Knife Game Pass. 46 00:02:50,790 --> 00:02:54,810 And then we need to do the same thing for our reload game pass as well. 47 00:02:55,170 --> 00:02:58,620 Back in the Game Pass section we'll go ahead and create another new game Pass. 48 00:02:58,620 --> 00:03:01,740 I'm going to call this one faster reload. 49 00:03:02,550 --> 00:03:04,650 And I'm going to say something like. 50 00:03:05,670 --> 00:03:14,130 This pass gives you a reload buff on all the guns in your inventory. 51 00:03:14,160 --> 00:03:18,060 We'll just say something like that, and then we can go ahead and add an image to this game pass as 52 00:03:18,060 --> 00:03:18,660 well. 53 00:03:19,170 --> 00:03:22,380 Here I've just added a very simple and basic image for my game pass. 54 00:03:22,380 --> 00:03:25,020 And then we can go ahead and hit Create Pass. 55 00:03:26,140 --> 00:03:31,120 And then we'll go inside of here, go to the sales section, place it for sale and we'll add in our 56 00:03:31,120 --> 00:03:31,510 price. 57 00:03:31,510 --> 00:03:36,700 I'll just do 99 Robux, we'll hit save, and then we can go ahead and copy that asset ID. 58 00:03:37,890 --> 00:03:41,760 And now back inside of studio, we'll create another new key inside of our enum. 59 00:03:41,760 --> 00:03:44,550 We'll call this one our Reload Game Pass. 60 00:03:44,550 --> 00:03:46,290 Set that equal to a table. 61 00:03:46,290 --> 00:03:53,580 The ID is going to be the one we just copied, and the name I will call it my Reload Game Pass. 62 00:03:55,880 --> 00:04:01,160 Okay, so now what I want to do is I want to create a new script inside of server script service. 63 00:04:01,160 --> 00:04:04,970 And this script is going to be my game pass handler. 64 00:04:04,970 --> 00:04:11,450 And we're going to be handling all of the events and prompting purchases for game passes inside of our 65 00:04:11,450 --> 00:04:14,690 game, using the same common template as before. 66 00:04:14,690 --> 00:04:18,290 We'll get rid of that section and we'll get rid of that section. 67 00:04:18,290 --> 00:04:24,620 And then we can go ahead and grab the service that's responsible for prompting Game Pass purchases to 68 00:04:24,620 --> 00:04:27,470 players, which is called the marketplace Service. 69 00:04:27,470 --> 00:04:33,470 We'll get the marketplace service that's equal to game get service marketplace service. 70 00:04:33,620 --> 00:04:36,680 And then we also want to grab the player service as well. 71 00:04:39,630 --> 00:04:43,740 And what we want to go ahead and do is we want to listen for when a player joins our game. 72 00:04:43,740 --> 00:04:49,290 So when a player is added, we'll connect a function and actually we'll create a dedicated function 73 00:04:49,290 --> 00:04:49,860 for this. 74 00:04:49,860 --> 00:04:51,750 We'll call it on player added. 75 00:04:51,750 --> 00:04:57,630 And the purpose of this function is to check to see if the player owns any of the game passes that are 76 00:04:57,630 --> 00:05:00,180 inside of our Game Pass enum. 77 00:05:00,180 --> 00:05:03,060 So let's go ahead and grab Replicated storage. 78 00:05:05,400 --> 00:05:09,660 And then we can go ahead and make a reference to our Game Pass enum. 79 00:05:09,660 --> 00:05:16,110 So we'll require replicated storage, dot modules, dot enums, dot game pass enum. 80 00:05:17,310 --> 00:05:24,120 And then we can connect our on player added function to this event, which will get passed a player. 81 00:05:24,120 --> 00:05:29,190 And then we want to check if this player owns any of the game passes in our Game Pass enum. 82 00:05:29,190 --> 00:05:33,780 So we're going to loop through every single game pass inside of our Game Pass enum. 83 00:05:34,320 --> 00:05:37,500 And we want to check if this player actually owns it. 84 00:05:37,500 --> 00:05:42,480 And the way we could do that is that inside of the marketplace service there is a function called user 85 00:05:42,480 --> 00:05:48,660 owns Game Pass async and it says returns true if the player with the given user ID owns the game pass 86 00:05:48,660 --> 00:05:50,280 with the given game pass ID. 87 00:05:50,370 --> 00:05:54,720 Now, since this is an asynchronous function, we're going to have to wrap it in a p call. 88 00:05:54,720 --> 00:05:56,070 So you know the deal. 89 00:05:56,070 --> 00:05:59,550 We'll get our success and result variable and that's equal to p call. 90 00:06:00,060 --> 00:06:01,470 We'll put a lambda function in there. 91 00:06:01,470 --> 00:06:03,390 And then we're going to copy this. 92 00:06:03,630 --> 00:06:07,410 And we're going to call the user owned Game Pass async function. 93 00:06:07,410 --> 00:06:09,930 The user ID is going to be our player's user ID. 94 00:06:09,930 --> 00:06:13,560 And then the game pass ID is going to be our game pass.id. 95 00:06:14,130 --> 00:06:17,310 And then we can go ahead and return that at the end of our function. 96 00:06:18,660 --> 00:06:22,530 And we can go ahead and check if we were successful with this pickle. 97 00:06:22,530 --> 00:06:27,360 If we were not successful and an error occurred that was outside of our control, then we'll just print 98 00:06:27,360 --> 00:06:34,860 something like error while attempting to check Game Pass status for player. 99 00:06:35,790 --> 00:06:38,640 And then we can just put the error on a new line. 100 00:06:38,640 --> 00:06:43,350 So we'll do backslash n and then concatenate that with the results from our p call. 101 00:06:43,560 --> 00:06:52,800 Otherwise if we were successful and this function returned true so else if result then we can go ahead 102 00:06:52,800 --> 00:06:59,130 and set an attribute on this player to let the entire game know hey, this player has this game pass. 103 00:07:00,520 --> 00:07:03,730 So we're going to do player set attribute. 104 00:07:03,880 --> 00:07:06,340 And we're going to be using the name of this game pass. 105 00:07:06,340 --> 00:07:11,320 So we'll refer to our Game Pass and get the name and set that attribute to true on our player. 106 00:07:11,320 --> 00:07:16,480 So now any script in our game can go ahead and check to see if this player has this attribute. 107 00:07:16,480 --> 00:07:19,570 And if they have this game pass and then act accordingly. 108 00:07:20,930 --> 00:07:24,710 Now one of those game passes was my golden knife. 109 00:07:24,710 --> 00:07:27,860 Let's go ahead and actually set up our golden knife. 110 00:07:27,860 --> 00:07:32,000 If we head to server storage and go into tools, we have our golden knife right here, but we haven't 111 00:07:32,000 --> 00:07:33,740 scripted anything inside of it. 112 00:07:33,740 --> 00:07:37,760 If I change the parent to the workspace and I go and find it, here's my golden knife. 113 00:07:37,760 --> 00:07:41,330 It's literally the exact same knife, except it's made out of gold. 114 00:07:41,330 --> 00:07:46,700 And what we should do with this knife is we should basically just copy all of these scripts that were 115 00:07:46,700 --> 00:07:52,100 inside of our regular knife, including the event will copy that, paste it inside of our golden knife. 116 00:07:52,100 --> 00:07:57,500 But this time we'll update the properties for the Golden knife to be more buffed like a better knife 117 00:07:57,500 --> 00:08:00,500 to use, and it swings faster and deals more damage. 118 00:08:01,540 --> 00:08:03,820 So I'll keep the damage the same. 119 00:08:03,820 --> 00:08:08,980 But actually what I want to do is I want to increase the chance of a critical hit for my player. 120 00:08:08,980 --> 00:08:10,300 And I'm going to above this a lot. 121 00:08:10,300 --> 00:08:14,500 I'm going to make it a 55% chance of getting a critical hit. 122 00:08:14,500 --> 00:08:17,320 And I'm also going to be increasing the critical hit multiplier. 123 00:08:17,320 --> 00:08:19,810 So the minimum will bump to like 1.4. 124 00:08:19,810 --> 00:08:22,750 And then the max we can bump to like 2.2. 125 00:08:22,750 --> 00:08:25,870 And then I don't want to impose any swing cooldowns. 126 00:08:25,870 --> 00:08:28,000 So I'll set this value to zero. 127 00:08:28,000 --> 00:08:31,870 And then I also want to decrease the duration of the animation as well. 128 00:08:31,870 --> 00:08:33,970 So we'll set this to like 0.25 seconds. 129 00:08:33,970 --> 00:08:39,970 So now we have a faster swinging knife that has a better chance of dealing critical hits and dealing 130 00:08:39,970 --> 00:08:41,020 more damage. 131 00:08:41,380 --> 00:08:46,090 So I'll go ahead and move my golden knife back inside of server storage. 132 00:08:47,060 --> 00:08:51,830 And now what we can do inside of our game pass handler is we can go ahead and listen for when a player 133 00:08:51,830 --> 00:08:53,540 has a character added to them. 134 00:08:53,540 --> 00:08:59,060 And then we can go ahead and check to see if the player is on the live team, and if they are, we'll 135 00:08:59,060 --> 00:09:01,430 give them this golden knife. 136 00:09:02,230 --> 00:09:07,480 So I'll create a function I'm going to call it on character added. 137 00:09:07,840 --> 00:09:11,260 And we'll get past a character to this function. 138 00:09:11,260 --> 00:09:16,600 And then with this player inside of the on player added event, what we're going to do is we're going 139 00:09:16,600 --> 00:09:19,750 to connect to their character added event. 140 00:09:19,750 --> 00:09:21,160 So we'll connect. 141 00:09:23,050 --> 00:09:25,900 Our on character added function to this event. 142 00:09:27,330 --> 00:09:31,950 And then inside of here we're going to get the player from the players. 143 00:09:31,980 --> 00:09:33,930 Um, get player from character function. 144 00:09:33,930 --> 00:09:36,270 So player is going to be equal to players. 145 00:09:36,270 --> 00:09:37,710 Get player from character. 146 00:09:37,710 --> 00:09:39,330 Pass the character here. 147 00:09:39,780 --> 00:09:46,080 And then we can go ahead and check to see if this player has the game pass the knife game pass. 148 00:09:46,080 --> 00:09:52,500 So if player get attribute and then we're going to use Game Pass enum dot knife game Pass. 149 00:09:52,500 --> 00:09:56,970 And we're going to check to see if this player owns the knife game pass. 150 00:09:56,970 --> 00:10:01,710 And if they do then the next thing we need to check is if the player is on the alive team. 151 00:10:01,710 --> 00:10:07,980 So if player dot team is equal to the alive team, let's go ahead and grab the team service. 152 00:10:10,320 --> 00:10:16,530 So if their team is equal to teams alive, then let's go ahead and give them the golden knife. 153 00:10:16,530 --> 00:10:19,020 So we're also going to need server storage. 154 00:10:22,020 --> 00:10:23,280 Server storage. 155 00:10:24,270 --> 00:10:28,650 And we'll go ahead and make a clone of server storage tools. 156 00:10:28,650 --> 00:10:34,590 Get the Golden knife, clone that, and then we'll set the parent of that clone equal to the player's 157 00:10:34,590 --> 00:10:35,610 backpack. 158 00:10:36,870 --> 00:10:42,210 So now if I play the game, since I'm the owner of the game, I'm automatically going to have or own 159 00:10:42,210 --> 00:10:47,640 all of the game passes, which means I should spawn with a golden knife inside of my inventory. 160 00:10:47,640 --> 00:10:49,500 So let's go ahead and play the game. 161 00:10:50,840 --> 00:10:56,420 And what I'm going to do is I'm actually going to head over to the player service and look at my character. 162 00:10:56,420 --> 00:11:02,390 And unfortunately, we don't have any attributes set on me, which is kind of interesting. 163 00:11:02,660 --> 00:11:07,400 If I spawn it to the map, I did not get my golden knife, which is strange. 164 00:11:07,400 --> 00:11:09,590 So let's go ahead and figure out why that's the case. 165 00:11:11,150 --> 00:11:14,090 I think it could be because we're testing in studio. 166 00:11:14,120 --> 00:11:19,040 The player might be added before the server is able to listen to the player added event. 167 00:11:19,040 --> 00:11:24,500 So just as a little bit of extra security, what I'm going to do is I'm going to loop through every 168 00:11:24,500 --> 00:11:25,790 player that's already in the game. 169 00:11:25,790 --> 00:11:28,670 So we'll do players, get players. 170 00:11:29,160 --> 00:11:35,640 And that way, if there's any players in the game that weren't able to be listened to because the player 171 00:11:35,640 --> 00:11:40,290 added event did not have this function connected to it yet, then we can go ahead and call our on player 172 00:11:40,290 --> 00:11:44,490 added function and pass our player to it. 173 00:11:45,130 --> 00:11:49,780 And then one last thing I want to make a minor change to is that since this is going to be yielding 174 00:11:49,780 --> 00:11:56,470 right here, I don't want to halt the main thread of execution and have it stuck yielding. 175 00:11:56,470 --> 00:12:01,660 So I'm actually going to spawn in a new thread. 176 00:12:02,600 --> 00:12:03,860 This code right here. 177 00:12:03,860 --> 00:12:05,180 So I'll do that. 178 00:12:05,180 --> 00:12:10,820 So that way for every single game pass we're checking, we are doing them all instantaneously at the 179 00:12:10,820 --> 00:12:12,170 same time for a player. 180 00:12:12,170 --> 00:12:18,500 Instead of having to sequentially go from one game pass to the next game pass, having to wait and yield 181 00:12:18,500 --> 00:12:21,830 for this function to return to us a result. 182 00:12:21,830 --> 00:12:23,690 So we're going to try it this way. 183 00:12:23,750 --> 00:12:26,060 And now if we go and play test the game. 184 00:12:27,690 --> 00:12:30,840 Hopefully if we go and take a look at our player. 185 00:12:31,660 --> 00:12:33,550 We still don't have the attributes. 186 00:12:33,550 --> 00:12:34,720 Very weird. 187 00:12:36,020 --> 00:12:40,910 Okay, so I found out what the issue was, which is a very strange issue. 188 00:12:40,910 --> 00:12:48,110 If I go to my knife game pass and I copy the asset ID directly from here, this is the ID that it gives 189 00:12:48,110 --> 00:12:48,530 me, right? 190 00:12:48,530 --> 00:12:50,990 We pasted it into our module script. 191 00:12:50,990 --> 00:12:58,430 However, if I go back and I copy the asset ID from here, take a look at this. 192 00:12:58,430 --> 00:13:01,010 The ID is completely different. 193 00:13:01,790 --> 00:13:04,040 And this is the ID that actually works. 194 00:13:04,040 --> 00:13:06,470 The other IDs were not working. 195 00:13:06,800 --> 00:13:08,270 Why this is the case? 196 00:13:08,270 --> 00:13:09,050 I have no idea. 197 00:13:09,050 --> 00:13:10,610 It must be a very weird bug. 198 00:13:10,610 --> 00:13:18,050 So what I advise for you to do is to go back to your game passes and copy the asset ID from here and 199 00:13:18,050 --> 00:13:19,700 not from here. 200 00:13:19,700 --> 00:13:23,060 I don't know why it's giving me two different asset ID numbers. 201 00:13:23,060 --> 00:13:29,120 That's very weird, but go ahead and copy your asset IDs from here and then it should be working. 202 00:13:29,970 --> 00:13:33,060 Okay, I just updated the two IDs for my game pass. 203 00:13:33,060 --> 00:13:35,220 They're completely different from the other ones I copied. 204 00:13:35,250 --> 00:13:43,680 I don't know why Roblox moment, but now if we go and play test our game and then we go back to my player, 205 00:13:43,680 --> 00:13:44,460 there we go. 206 00:13:44,460 --> 00:13:50,010 Now it says that I own both the knife game pass and the reload game pass, and if I go and play test 207 00:13:50,010 --> 00:13:52,080 my game, there we go. 208 00:13:52,080 --> 00:13:54,900 I get spawned with the Golden knife. 209 00:13:54,900 --> 00:13:55,800 Very cool. 210 00:13:57,420 --> 00:14:03,300 Okay, the next game pass that I want to script for is going to be the faster reload game pass. 211 00:14:03,300 --> 00:14:08,430 And this one's going to be a little bit trickier, because what we need to do is we need to update the 212 00:14:08,430 --> 00:14:13,530 properties module script for our gun on both the client and on the server. 213 00:14:13,530 --> 00:14:18,870 So that means if the server finds that a player has a gun in their inventory, the server needs to update 214 00:14:18,870 --> 00:14:25,050 the reload duration on the server side and then tell the client to update the reload duration on their 215 00:14:25,050 --> 00:14:29,940 side as well, because again, the module scripts ones on the server, ones on the client, they're 216 00:14:29,940 --> 00:14:33,630 going to be two different module scripts that both need to be updated. 217 00:14:34,510 --> 00:14:40,840 So in order to account for that, we can use the exact same gun event that the guns use and instead 218 00:14:40,840 --> 00:14:45,880 fire to a client to a specific gun that needs to be updated with its reload duration. 219 00:14:45,880 --> 00:14:49,270 And then we can listen from the local script that is inside of our gun. 220 00:14:49,270 --> 00:14:53,410 When the server tells us to update the reload duration, we'll do that on the client side, and then 221 00:14:53,410 --> 00:14:57,010 the server updates the reload duration on the server side as well. 222 00:14:57,690 --> 00:15:02,430 So that means what I want to do is I want to check if my player. 223 00:15:02,460 --> 00:15:03,600 Get attribute. 224 00:15:03,600 --> 00:15:06,660 They have the faster reload. 225 00:15:06,660 --> 00:15:08,250 So reload game pass. 226 00:15:08,250 --> 00:15:14,460 If they own that game pass then we want to listen for when a child is added to the player's character. 227 00:15:14,460 --> 00:15:20,550 And the reason for that is we need to check if that child is a gun, and if it is, we want to tell 228 00:15:20,550 --> 00:15:25,950 the client to update the reload duration property for that particular gun. 229 00:15:25,950 --> 00:15:27,060 So. 230 00:15:28,370 --> 00:15:31,010 When the character has a child added to them. 231 00:15:31,010 --> 00:15:35,570 We're going to connect a function to this which is going to be on, child added. 232 00:15:35,570 --> 00:15:40,010 So we'll create a new function, call it on, child added. 233 00:15:40,010 --> 00:15:44,870 We'll get past the child and we need to check to see if this child is a tool. 234 00:15:44,870 --> 00:15:50,300 So if this child is not a tool, is a tool then we're going to return. 235 00:15:51,190 --> 00:15:55,480 If this child is a tool, but it's not a gun, then we're also going to return. 236 00:15:55,480 --> 00:16:03,010 So if not child get attribute gun type then we also need to return. 237 00:16:03,010 --> 00:16:09,340 And then another thing we need to keep track of is if we've already buffed the reload duration for this 238 00:16:09,340 --> 00:16:10,330 particular gun. 239 00:16:10,330 --> 00:16:13,600 So what we can go ahead and do is set an attribute on this child. 240 00:16:13,600 --> 00:16:18,670 Once the server has a buffed the reload duration and set to say something like it's already been reload 241 00:16:18,670 --> 00:16:19,030 buffed. 242 00:16:19,030 --> 00:16:24,610 So that way when the player equips the tool and then re equips it, we don't accidentally buff the reload 243 00:16:24,610 --> 00:16:26,350 duration again on the gun. 244 00:16:26,680 --> 00:16:30,970 So what we can go ahead and do is set an attribute on this gun. 245 00:16:30,970 --> 00:16:33,820 And we're going to call it something like reload buffed. 246 00:16:35,670 --> 00:16:36,810 And we'll set that to true. 247 00:16:36,810 --> 00:16:42,900 And that way we can go ahead and check if this child already has the attribute of reload buffed. 248 00:16:42,900 --> 00:16:45,540 And if it does, then we're going to return. 249 00:16:45,870 --> 00:16:50,340 Otherwise we can go ahead and get the player that has this gun equipped. 250 00:16:50,340 --> 00:16:54,570 So we're going to do players get player from character. 251 00:16:54,570 --> 00:16:56,970 And that's going to be the parent of this child. 252 00:16:58,410 --> 00:17:01,440 And then we're going to grab the properties for this gun. 253 00:17:01,440 --> 00:17:03,060 So we'll require. 254 00:17:03,760 --> 00:17:06,340 Child that properties since it's a gun. 255 00:17:08,000 --> 00:17:11,960 And then we can go ahead and update the properties reload duration. 256 00:17:11,960 --> 00:17:18,620 And since we want to make the reload duration 35% faster, let's go ahead and define a constant up here. 257 00:17:20,250 --> 00:17:23,010 And I'll call this constant reload percent. 258 00:17:23,010 --> 00:17:25,350 And we're going to set it to 0.65. 259 00:17:25,350 --> 00:17:30,210 And then we can go ahead and multiply our reload duration by this value to make the reload duration 260 00:17:30,210 --> 00:17:31,710 35% faster. 261 00:17:31,710 --> 00:17:35,430 So we'll do times equal reload percent. 262 00:17:35,640 --> 00:17:42,450 And then here we could use the gun event that's inside of replicated storage to tell this player, hey, 263 00:17:42,450 --> 00:17:47,040 you need to update the property for this particular gun on your side as well. 264 00:17:47,160 --> 00:17:50,940 So let's go ahead and make a reference to that gun event. 265 00:17:50,940 --> 00:17:53,910 So replicated storage dot remotes dot gun event. 266 00:17:55,270 --> 00:18:01,090 And I want to hop into my gun comms enum, and then I want to create a section for actions to be given 267 00:18:01,090 --> 00:18:02,350 to the client. 268 00:18:02,500 --> 00:18:05,710 And this action I'm going to call it Update property. 269 00:18:05,710 --> 00:18:10,900 So that way the client knows to update a property on their gun and then back inside of our game pass 270 00:18:10,900 --> 00:18:17,710 handler we can go ahead and grab the gun comms enum, so we'll require replicated storage, dot modules, 271 00:18:17,710 --> 00:18:19,750 dot enums, dot gun comms enum. 272 00:18:20,020 --> 00:18:23,680 And then we'll use the gun event fire to this particular player. 273 00:18:23,680 --> 00:18:25,180 So we'll pass the player here. 274 00:18:25,180 --> 00:18:32,110 We'll give them the action which is going to be gun comms enum dot two client dot update property. 275 00:18:32,410 --> 00:18:37,150 And we also want to let them know which particular gun they need to update. 276 00:18:37,150 --> 00:18:41,710 And that's because if the player has multiple different guns, then all of those guns are going to be 277 00:18:41,710 --> 00:18:43,270 listening to this event. 278 00:18:43,270 --> 00:18:48,070 So we only want to fire this to a particular gun in their inventory. 279 00:18:48,070 --> 00:18:53,290 And the easiest way for us to do that is simply just to pass the tool itself to the player. 280 00:18:53,290 --> 00:18:56,740 So the player knows exactly which gun to update. 281 00:18:58,060 --> 00:19:01,000 And then we could pass the property. 282 00:19:01,000 --> 00:19:06,220 They need to update on that gun, which would be the reload duration, and then we can tell them what 283 00:19:06,220 --> 00:19:09,370 value we would like them to set that reload duration to. 284 00:19:09,370 --> 00:19:13,330 And that's just going to be equal to the reload duration that is on the server. 285 00:19:15,200 --> 00:19:19,250 But now what we need to do is we need to hop into one of the local scripts for our gun. 286 00:19:19,250 --> 00:19:26,750 I'll just do it for the AR, and then we'll go down to the handler section, and we want to listen for 287 00:19:26,750 --> 00:19:29,510 when our gun event is fired on the client. 288 00:19:29,510 --> 00:19:33,890 So on client event we'll connect a function to this. 289 00:19:34,310 --> 00:19:37,280 And the server is going to be passing to us the action. 290 00:19:37,280 --> 00:19:40,820 And then they're going to pass us the particular gun they want us to update. 291 00:19:40,820 --> 00:19:43,610 So we'll call this passed gun the property. 292 00:19:43,610 --> 00:19:46,580 And then the value we want to update to that property. 293 00:19:47,290 --> 00:19:54,040 So first thing we want to check is if this passed gun the server is giving to us is equal to the same 294 00:19:54,040 --> 00:19:56,050 gun that this local script is in. 295 00:19:56,050 --> 00:20:02,500 So if the passed gun is not equal to the gun that's referred to in this local script, then we're just 296 00:20:02,500 --> 00:20:05,380 going to return and ignore it for this particular gun. 297 00:20:05,380 --> 00:20:08,440 Otherwise we can check if the action is equal to the gun. 298 00:20:08,440 --> 00:20:10,930 Comms enum of two client. 299 00:20:11,570 --> 00:20:17,390 Dot update property, and if it is, then we can just simply refer to the properties inside of our gun 300 00:20:17,390 --> 00:20:22,400 and update this particular property the server wants us to update with this new value. 301 00:20:22,950 --> 00:20:29,430 And just like that, we should now have implemented a reload buff to all of the guns in our game. 302 00:20:29,670 --> 00:20:35,880 So what I'm going to do is I'm going to copy this new local script and put it inside of all of my guns, 303 00:20:35,880 --> 00:20:39,900 and I'll go ahead and get rid of the old local script for my guns. 304 00:20:39,900 --> 00:20:43,860 So we'll just delete that old one, get rid of that one, that one. 305 00:20:43,860 --> 00:20:45,660 Delete, delete and delete. 306 00:20:46,830 --> 00:20:52,200 And then just to quickly test this out, I'm going to copy the R and put it inside of the starter pack. 307 00:20:52,530 --> 00:20:58,080 And then to try to make this reload duration as prominent as possible. 308 00:20:58,080 --> 00:21:00,810 So we can tell to see if the reload buff got applied to us. 309 00:21:00,810 --> 00:21:03,630 I'm going to set the reload percent to like one. 310 00:21:03,630 --> 00:21:06,540 So our reload duration should be like 90% faster. 311 00:21:06,540 --> 00:21:08,130 So let's go ahead and see if that worked. 312 00:21:08,130 --> 00:21:09,420 If we play the game. 313 00:21:11,160 --> 00:21:13,680 And then we go and hop into the game. 314 00:21:14,640 --> 00:21:17,850 I got my assault rifle, and if I shoot and then reload. 315 00:21:18,630 --> 00:21:21,840 Yeah, you can see our reload duration was much faster. 316 00:21:21,870 --> 00:21:22,890 Let's try that again. 317 00:21:23,460 --> 00:21:26,670 And as you can see, look how fast reload is. 318 00:21:28,020 --> 00:21:30,390 Obviously that's a reload duration. 319 00:21:30,390 --> 00:21:32,310 That's too fast for my taste. 320 00:21:32,520 --> 00:21:41,100 I much prefer the 35% buff, but at least we know that the reload buff is actually working for any players 321 00:21:41,100 --> 00:21:45,150 in our game that have the Reload Buff game pass. 322 00:21:46,210 --> 00:21:52,930 So the next thing that we need to go ahead and do is we need to script the functionality for the player 323 00:21:52,930 --> 00:21:58,960 to interact with the GUI, to buy game passes, and then we need to listen on the server when the player 324 00:21:58,960 --> 00:22:00,790 actually purchases those game pass. 325 00:22:00,790 --> 00:22:06,220 And if they do purchase it, we need to set those attributes on our player to true in real time, because 326 00:22:06,220 --> 00:22:10,720 we don't want to force our player to have to rejoin the game in order to get their benefits. 327 00:22:11,360 --> 00:22:15,170 So let's go ahead and go back into the local script for our starting menu. 328 00:22:15,200 --> 00:22:16,190 We'll open that up. 329 00:22:16,950 --> 00:22:23,280 And then we want to go ahead and listen to all the stuff that's going to be inside of our shop. 330 00:22:23,280 --> 00:22:28,050 Specifically, when the player presses the shot button, we want to display the shop onto their screen, 331 00:22:28,050 --> 00:22:30,870 and when they press the close button, we want to close the shop. 332 00:22:30,870 --> 00:22:36,480 And if they press one of the buy buttons for one of the game passes, then we'll fire to the server. 333 00:22:36,480 --> 00:22:42,240 Hey, we want to purchase this particular game Pass, so let's actually go ahead and grab the Game Pass 334 00:22:42,240 --> 00:22:47,790 enum here in this local script will require and get and replicated storage modules dot enums dot game 335 00:22:47,790 --> 00:22:48,780 pass enum. 336 00:22:49,900 --> 00:22:55,870 And then we'll go down to our handlers section, and we'll make a little section here for listening 337 00:22:55,900 --> 00:22:57,850 to events for our shop. 338 00:22:58,000 --> 00:23:03,280 And I want to kind of segregate it and be able to collapse it and hide it, just to make my script more 339 00:23:03,280 --> 00:23:03,910 organized. 340 00:23:03,910 --> 00:23:06,700 And the easiest way to do that would be to create a new scope. 341 00:23:07,210 --> 00:23:11,980 And the easiest way to create a new scope would just be to type du and then hit enter. 342 00:23:12,280 --> 00:23:16,840 And what I've done right here is just made a little new scope that I'm able to collapse. 343 00:23:16,840 --> 00:23:19,930 And any variables I make inside of this scope. 344 00:23:19,930 --> 00:23:25,810 For example, this is a variable right here since it's local to this particular scope right here, I 345 00:23:25,810 --> 00:23:29,380 can't access the example variable outside of that scope. 346 00:23:30,090 --> 00:23:34,950 So inside of my little scope, I want to listen for when my shot button is activated. 347 00:23:35,640 --> 00:23:41,370 And when that happens, we want to go ahead and make the shot frame visible on the player screen. 348 00:23:42,100 --> 00:23:45,460 And then inside of our shop frame we have a close button. 349 00:23:45,700 --> 00:23:49,720 We want to listen for when that is activated and when the player presses that. 350 00:23:49,720 --> 00:23:53,470 We'll go ahead and refer to our shop frame and set visible back to false. 351 00:23:54,490 --> 00:23:59,440 And then inside of the shop frame, we have our container frame that contains all of the different frames 352 00:23:59,440 --> 00:24:00,640 for the game passes. 353 00:24:00,640 --> 00:24:05,710 For example, one of them is going to be our faster reload frame, and inside of there we have a buy 354 00:24:05,710 --> 00:24:06,460 button. 355 00:24:06,550 --> 00:24:10,660 And we'll go ahead and listen for when that is activated and when it is. 356 00:24:10,690 --> 00:24:15,490 This is where we could fire an event to the server to prompt a purchase to us. 357 00:24:15,760 --> 00:24:22,750 So inside of replicated storage, I have another remote event inside of the GUI folder called Buy Game 358 00:24:22,750 --> 00:24:23,440 Pass. 359 00:24:23,530 --> 00:24:25,750 Let's go ahead and make a reference to that real quick. 360 00:24:26,780 --> 00:24:28,340 I'll create a new variable. 361 00:24:28,340 --> 00:24:34,280 I'll call it Game Pass Event and that's replicated storage, dot remotes, dot guy dot game pass or 362 00:24:34,280 --> 00:24:35,390 by Game Pass. 363 00:24:36,480 --> 00:24:42,810 And then we can go ahead and use this Game Pass event and fire to the server. 364 00:24:43,080 --> 00:24:49,110 And then we can tell them which game pass we would like to purchase by passing the ID of the Game Pass. 365 00:24:49,110 --> 00:24:50,940 So we'll use our Game Pass enum. 366 00:24:51,760 --> 00:24:54,310 And we'll use for this case. 367 00:24:54,310 --> 00:24:58,030 It's going to be the reload game pass and we'll just pass the ID to the server. 368 00:24:58,740 --> 00:25:00,960 And I'm going to copy this, paste this here. 369 00:25:00,960 --> 00:25:05,730 And we want to do the same thing for the Golden Knife Game Pass. 370 00:25:05,730 --> 00:25:09,870 And this time we're going to tell the server that we would like to purchase the Knife Game Pass. 371 00:25:09,870 --> 00:25:14,610 So now what we need to do on the server is listen for when this Game Pass event is fired. 372 00:25:14,610 --> 00:25:19,140 And when the player tells us they want to purchase a game pass, we're going to prompt a purchase to 373 00:25:19,140 --> 00:25:19,560 them. 374 00:25:20,460 --> 00:25:22,740 The backhand side of our game pass handler. 375 00:25:22,740 --> 00:25:27,930 Well, we can go ahead and do is we can listen for when our Game Pass event is fired. 376 00:25:27,930 --> 00:25:30,660 And that means we're actually going to need to make a variable for it. 377 00:25:30,660 --> 00:25:37,830 So we'll get our Game Pass event that's replicated storage dot events or remotes GUI dot. 378 00:25:38,800 --> 00:25:39,970 Game pass or buy. 379 00:25:40,000 --> 00:25:40,600 Game pass. 380 00:25:40,600 --> 00:25:41,290 There we go. 381 00:25:42,420 --> 00:25:49,530 And then Game Pass event will listen for on server event, connect a function, get the player and then 382 00:25:49,530 --> 00:25:52,770 the ID of the game pass they want to purchase. 383 00:25:53,570 --> 00:25:58,580 And then what we want to go ahead and do is we want to loop through all of the game passes in our enum 384 00:25:58,580 --> 00:26:05,180 and check to see if the ID the player passed to us actually belongs to one of the game passes in our 385 00:26:05,180 --> 00:26:06,290 Game Pass enum. 386 00:26:06,290 --> 00:26:13,970 So for every single game pass inside of our Game Pass enum, what we want to do is we want to check 387 00:26:13,970 --> 00:26:21,230 if this game pass ID, so if game pass ID if it's not equal to this game passes. 388 00:26:22,270 --> 00:26:25,960 Uh, ID then we'll just continue to the next game pass. 389 00:26:26,320 --> 00:26:32,290 Otherwise, if we found a matching game pass, then we can go ahead and use the marketplace service. 390 00:26:32,290 --> 00:26:36,310 And there's a function in there called Prompt Game Pass purchase. 391 00:26:36,310 --> 00:26:40,990 And we need to pass the player and then the ID for the game pass. 392 00:26:40,990 --> 00:26:43,180 So we'll pass our player here. 393 00:26:43,630 --> 00:26:46,720 And then we can go ahead and pass the game pass.id. 394 00:26:47,830 --> 00:26:51,310 And once we do that, we can go ahead and just break out of this loop because there's no reason for 395 00:26:51,310 --> 00:26:55,630 us to continue looping through the other game passes because we found the one that the player wanted 396 00:26:55,630 --> 00:26:56,560 to purchase. 397 00:26:56,890 --> 00:27:01,810 So when we call this function on the client side, a little pop up window is going to appear to tell 398 00:27:01,810 --> 00:27:03,610 them to purchase the Game Pass. 399 00:27:03,610 --> 00:27:08,560 And if they purchase it, then it's going to notify us on the server and there's an event for that. 400 00:27:09,070 --> 00:27:15,310 There is an event inside of the marketplace service called Prompt Game Pass Purchase finished. 401 00:27:15,310 --> 00:27:18,580 So we're going to connect a function to this. 402 00:27:19,130 --> 00:27:25,520 And this function is going to be passed to the player what the game pass ID was and whether or not they 403 00:27:25,520 --> 00:27:27,080 purchased the game pass. 404 00:27:27,080 --> 00:27:33,710 So we'll get the player the ID of the game pass, and then it'll tell us whether or not it was purchased. 405 00:27:35,020 --> 00:27:40,030 So now what we can go ahead and do is we can again loop through all of the game passes in our Game Pass 406 00:27:40,030 --> 00:27:40,660 enum. 407 00:27:41,560 --> 00:27:47,470 And if this ID is not equal to this game pass ID, then we'll just continue looping to the next game 408 00:27:47,470 --> 00:27:51,370 pass until we eventually find which game pass they purchased. 409 00:27:51,370 --> 00:27:56,140 And if we've confirmed that they've purchased the Game Pass, then we can go ahead and set an attribute 410 00:27:56,140 --> 00:27:58,900 on this player for this particular game Pass. 411 00:27:58,900 --> 00:28:04,600 And we'll just use the Game Pass dot name and set that equal to true. 412 00:28:04,600 --> 00:28:08,530 And of course we only want to do this if they actually purchased the Game Pass. 413 00:28:08,530 --> 00:28:14,020 So if they did not purchase the Game Pass then we're just going to return and ignore this player. 414 00:28:14,020 --> 00:28:18,550 Otherwise if they did purchase the game pass, then we're going to set that attribute on our player 415 00:28:18,550 --> 00:28:19,210 to true. 416 00:28:19,210 --> 00:28:24,670 And then because we're setting that attribute on them, any time they spawn into the game, we're going 417 00:28:24,670 --> 00:28:29,020 to be giving them their golden knife or any time they have a gun added to their inventory. 418 00:28:29,020 --> 00:28:33,400 If it's the reload game pass, we're going to be buffing the reload for them. 419 00:28:33,930 --> 00:28:37,680 So let's go ahead and test to see if all of this is working. 420 00:28:38,220 --> 00:28:39,750 We'll go and play test our game. 421 00:28:41,110 --> 00:28:44,380 And we should be able to open up our store if we hit this button. 422 00:28:44,410 --> 00:28:45,070 There we go. 423 00:28:45,070 --> 00:28:46,120 Our store is open. 424 00:28:46,120 --> 00:28:48,400 We have our golden knife and our fast reload. 425 00:28:48,400 --> 00:28:51,700 I didn't upload any images for these two frames. 426 00:28:51,700 --> 00:28:56,590 If you want to go ahead and insert your own images inside of the GUI, you're more than welcome to do 427 00:28:56,590 --> 00:28:57,040 that. 428 00:28:57,040 --> 00:29:01,150 But we want to test if the server is going to prompt us to purchase the Game Pass. 429 00:29:01,150 --> 00:29:02,650 So if I hit this buy button. 430 00:29:03,630 --> 00:29:04,200 There we go. 431 00:29:04,200 --> 00:29:05,520 It says you already own this item. 432 00:29:05,520 --> 00:29:06,840 Your account has not been charged. 433 00:29:06,840 --> 00:29:10,500 Which is, of course, what I would expect because I already own the Game pass. 434 00:29:10,500 --> 00:29:14,610 But as you can see, it is working when we press these buy buttons. 435 00:29:16,350 --> 00:29:17,490 You already own this item. 436 00:29:17,490 --> 00:29:21,420 Your account has not been charged, so we're not able to purchase them because it's like, what are 437 00:29:21,420 --> 00:29:21,690 you doing? 438 00:29:21,690 --> 00:29:23,760 You already you already own the game pass, right? 439 00:29:25,390 --> 00:29:31,870 And if we go and playtest our game, I've got my golden knife ready to slay some zombies. 440 00:29:31,870 --> 00:29:34,300 So let's go ahead and actually test out our golden knife. 441 00:29:35,110 --> 00:29:37,570 This thing should be a lot better than the regular knife. 442 00:29:37,570 --> 00:29:42,730 So if I stab this guy, hopefully I get a critical hit here. 443 00:29:45,490 --> 00:29:48,340 It also swings a lot faster than the regular knife. 444 00:29:48,340 --> 00:29:52,090 So if I swing the regular knife, that's how fast I can swing it. 445 00:29:52,090 --> 00:29:58,540 And then with the golden knife, as you can see, I can swing it a lot faster and it does deal a lot 446 00:29:58,540 --> 00:29:59,680 more damage. 447 00:29:59,680 --> 00:30:00,220 Yeah. 448 00:30:03,280 --> 00:30:07,180 Of course, you can further buff the damage and the critical hit rate of this golden knife. 449 00:30:07,180 --> 00:30:10,180 Do whatever you want, change your game however you want. 450 00:30:10,180 --> 00:30:13,060 It's totally up to your creative preference. 451 00:30:15,510 --> 00:30:17,790 Let's go ahead and clear out all these zombies. 452 00:30:21,300 --> 00:30:23,850 I got a one hit shot on that zombie right there. 453 00:30:29,430 --> 00:30:32,250 Oh, it looks like I forgot to reset the value back to one. 454 00:30:32,250 --> 00:30:33,270 So it says game over. 455 00:30:33,270 --> 00:30:34,230 You win. 456 00:30:35,330 --> 00:30:37,910 So I need to actually go back. 457 00:30:37,910 --> 00:30:38,630 And it killed me. 458 00:30:38,630 --> 00:30:45,800 I need to go back to my game handler and make sure I actually reset the total waves back to 11. 459 00:30:45,800 --> 00:30:51,890 And then I'm going to reset the intermission back to its regular value of 60, and then the start intermission 460 00:30:51,890 --> 00:30:53,360 back to its value of 30. 461 00:30:55,310 --> 00:30:55,940 Otherwise. 462 00:30:55,940 --> 00:31:00,560 That is how we can implement game passes into our game. 463 00:31:00,560 --> 00:31:04,610 I hope you're enjoying the project so far and I'll see you in the next lecture.